package com.wyc.controller;

import com.wyc.pojo.Dept;
import com.wyc.pojo.Result;
import com.wyc.service.DeptsService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;


@RestController
@Slf4j
public class DeptsController {
    @Autowired
    private DeptsService deptsService;


    @GetMapping("depts")
    public Result list(){
        return Result.success(deptsService.selectAllDepts());
    }


    /**
     * 删除部门
     * @return
     */
    @DeleteMapping("/depts/{id}")
    public Result deleteById(@PathVariable Integer id) throws Exception {

         deptsService.deleteById(id);
         return Result.success();
    }
    /**
     * 添加部门
     */
    @PostMapping("/depts")
    public Result add(@RequestBody Dept dept){
        deptsService.add(dept);
        return Result.success();
    }

}


